﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation.Regions;
using System;

namespace MainApp.ViewModels
{
    public class MainWindowViewModel :BindableBase
    {
        private readonly IRegionManager _regionManager;

        private string _title = "工具";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        private string _selectedPage;
        public string SelectedPage
        {
            get => _selectedPage;
            set => SetProperty(ref _selectedPage, value);
        }

        public DelegateCommand<string> NavigateCommand { get; }

        public MainWindowViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;
            // 初始化命令，接收页面名称作为参数
            NavigateCommand = new DelegateCommand<string>(ExecuteNavigate);
            
        }
        
        private void ExecuteNavigate(string pageName)
        {
            if (!string.IsNullOrEmpty(pageName))
            {
                SelectedPage = pageName; // 设置选中状态
                // 使用 Prism 进行页面导航
                _regionManager.RequestNavigate("ContentRegion", pageName);
            }
        }
    }
}
